import 'package:flutter/material.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_model/mine/excharge/recharge_type_list_model.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

class CoinItem extends StatelessWidget {
  final RechargeTypeModel model;
  final bool select;
  final Function()? onTap;
  const CoinItem(this.model, {super.key, this.onTap, this.select = false});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => onTap?.call(),
      child: Stack(
        children: [
          Container(
            width: double.infinity,
            margin: EdgeInsets.only(top: 10),
            decoration: BoxDecoration(
              color: Colors.white.withOpacity(.1),
              borderRadius: BorderRadius.circular(8),
              border: select ? Border.all(width: 1, color: Color(0xffF9C142)) : null,
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Image.asset('coin_icon.png'.mineImgPath, width: 36),
                4.sizeBoxH,
                Text(
                  "${model.amount}金币",
                  style: TextStyle(
                    color: Color(0xff989898),
                    fontSize: 14,
                  ),
                ),
                4.sizeBoxH,
                Text(
                  '${(model.money ?? 0) ~/ 100}RMB',
                  style: TextStyle(
                    color: Color(0xffF9C142),
                    fontWeight: FontWeight.w500,
                  ),
                ),
                4.sizeBoxH,
              ],
            ),
          ),
          if (model.couponDesc != null && (model.couponDesc?.isNotEmpty ?? false))
            Positioned(
              top: 0,
              left: 0,
              right: 0,
              child: LayoutBuilder(
                builder: (__, ___) {
                  return ConstrainedBox(
                    constraints: ___,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: Container(
                        height: 20,
                        padding: EdgeInsets.symmetric(horizontal: 5, vertical: 5),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.only(topLeft: Radius.circular(12), bottomRight: Radius.circular(12)),
                          color: Color(0xffFFD460),
                        ),
                        child: Text(
                          "${model.couponDesc}",
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                            color: Color(0xff292929),
                            fontWeight: FontWeight.w500,
                            height: 1,
                            fontSize: 10.0,
                          ),
                        ),
                      ),
                    ),
                  );
                },
              ),
            ),
        ],
      ),
    );
  }
}
